#include "ticketchangeset.h"

#include <QDebug>

TicketAction::TicketAction(const QString &action, const QString &label, const QString &hint)
    : m_action(action), m_label(label), m_hint(hint), m_inputFieldName(""), m_inputFieldValue("")
{
}

TicketAction::TicketAction(const QString &action, const QString &label, const QString &hint,
             const QString &inputName, const QString &inputValue,
             const QStringList &allowedFields)
    : m_action(action), m_label(label), m_hint(hint), m_inputFieldName(inputName),
      m_inputFieldValue(inputValue), m_allowedFields(allowedFields)
{
}

QString TicketAction::action() const
{
    return m_action;
}

QString TicketAction::label() const
{
    return m_label;
}

QString TicketAction::hint() const
{
    return m_hint;
}

QString TicketAction::inputName() const
{
    return m_inputFieldName;
}

QString TicketAction::inputValue() const
{
    return m_inputFieldValue;
}

QStringList TicketAction::allowedFields() const
{
    return m_allowedFields;
}

TicketAction *TicketAction::dup()
{
    return new TicketAction(m_action, m_label, m_hint, m_inputFieldName,
                            m_inputFieldValue, m_allowedFields);
}

QDebug operator<<(QDebug debug, const TicketAction *action)
{
    debug << "Action: " << action->action() << " (" << action->label()
             << ", " << action->hint() << ")\n";
    if (action->inputName() != "")
        debug << "input field: " << action->inputName() << " = " << action->inputValue()
                 << " (" << action->allowedFields() << ")";
    return debug;
}

TicketChangeset::TicketChangeset(const QDateTime &timestamp, const QString &author)
{
    m_timestamp = timestamp;
    m_author = author;
}

void TicketChangeset::addField(const QString &field, const QVariant &value,
                               const QVariant &oldValue)
{
    m_fields.insert(field, FieldValue(value, oldValue));
}

QDateTime TicketChangeset::timestamp() const
{
    return m_timestamp;
}

QString TicketChangeset::author() const
{
    return m_author;
}

FieldMap TicketChangeset::changedFields() const
{
    return m_fields;
}


void TicketAction::setInputFieldName(const QString &name)
{
    m_inputFieldName = name;
}


void TicketAction::setInputFieldValue(const QString &value)
{
    m_inputFieldValue = value;
}

void TicketAction::setAllowedFields(const QStringList &fields)
{
    m_allowedFields = fields;
}


